<cfcomponent output="false" extends="mof.AbstractController">


	<cffunction name="configure" access="private" output="false" returntype="void">
		<cfreturn />
	</cffunction>


	<!--- 
	####################################################################
	EVENT HANDLERS
	####################################################################--->
	<cffunction name="index" access="public" output="false" returntype="void">
		<cfset setArg("pageTitle","MOF examples.") />
		
		<cfreturn />
	</cffunction>
	
	<cffunction name="form" access="public" output="false" returntype="void">
		<cfset setArg("pageTitle","MOF form submit/redirect example.") />
		<cfset setArg("MyArg","This is the content at the top") />
		<cfreturn />
	</cffunction>
	
	<cffunction name="formsubmit" access="public" output="false" returntype="void">
		<cfset setArg("MyOtherArg","This was set on the submit event, but is carried back to the initial view.") />
		<cfset redirect("examples","form") />
		<cfreturn />
	</cffunction>

	
	<cffunction name="viewstacks" access="public" output="false" returntype="void">
		<cfset setArg("pageTitle","MOF Custom ViewStack Examples") />
		<cfset appendViewStack(buildView("examples.loginform"),"sidebar") />
		<cfset setArg("recentEntries",getRecentEntries()) />
		<cfset appendViewStack(buildView("examples.recententries"),"sidebar") />
	</cffunction>
	
	<cffunction name="ajax" access="public" output="false" returntype="void">
		<cfset setArg("pageTitle","MOF jQuery Ajax Example") />
		<cfreturn />
	</cffunction>
	
	<cffunction name="loadtime" access="public" output="false" returntype="void">
		<cfset appendViewStack(TimeFormat(getArg("now"),"full")) />
		<cfset setLayout("layout.raw") />
		<cfreturn />
	</cffunction>

	<cffunction name="dump" access="public" output="false" returntype="void">
		<cfset setArg("pageTitle","MOF property/arg dumper") />
		<cfset setArg("someCoolArg","Hey this really is cool!") />
		<cfreturn />
	</cffunction>	
	
	<cffunction name="securepage" access="public" output="false" returntype="void">
		<!--- 
		this subroutine can be found in /subroutines.  It checks to the session variable "isLoggedIn"
		and will redirect the user to examples/login if not.
		 --->
		<cfset execute("ExampleCheckLoginSubroutine") />
		<cfreturn />
	</cffunction>
	
	<cffunction name="loginform" access="public" output="false" returntype="void">
		<cfset setArg("usernameHint","use: <em>""admin""</em>") />
		<cfset setArg("passwordHint","use: <em>""pass""</em>") />
		<cfreturn />
	</cffunction>
	
	<cffunction name="loginsubmit" access="public" output="false" returntype="void">
		<cfif getArg("username") EQ "admin" AND getArg("password") EQ "pass">
			<cfset session.isLoggedIn = true />
			<cfset setArg("message","Welcome #getArg("username")#!") />
			<cfset redirect("examples","securepage") />
		<cfelse>		
			<cfset setArg("message","Sorry, that login is incorrect.") />
			<cfset redirect("examples","loginform") />
		</cfif>
		<cfreturn />
	</cffunction>
	
	<cffunction name="logout" access="public" output="false" returntype="void">
		<cfset StructDelete(session,"isLoggedIn") />
		<cfset redirect("examples","securepage") />
		<cfreturn />
	</cffunction>	
	
	<!--- 
	####################################################################
	PRIVATE METHODS
	####################################################################--->
	<cffunction name="getRecentEntries" access="private" output="false" returntype="query">
		<cfset var recentEntries = QueryNew("title,link") />
		
		<cfset QueryAddRow(recentEntries) />
		<cfset QuerySetCell(recentEntries,"title","Damn Small Framework.") />
		<cfset QuerySetCell(recentEntries,"link","damn_small_framework") />
		<cfset QueryAddRow(recentEntries) />
		<cfset QuerySetCell(recentEntries,"title","How Small Is It?") />
		<cfset QuerySetCell(recentEntries,"link","how_small_is_id") />
		<cfset QueryAddRow(recentEntries) />
		<cfset QuerySetCell(recentEntries,"title","Do I need a Microscope?") />
		<cfset QuerySetCell(recentEntries,"link","do_i_need_a_microscope") />
		<cfreturn recentEntries />	
	</cffunction>
	
</cfcomponent>